package com.cynteka.cyfoman.core.collection;

import com.cynteka.cyfoman.core.Task;

import java.util.Collection;

/**
 * User: Sergey
 * Date: 02.08.11
 * Time: 23:48
 */
public class CollectionScanner implements Task {

    private CollectionRegistry collectionRegistry;
    private String collectionId;
    private ICollectionHandler collectionHandler;

    public int getCountItemsToFire() {
        return countItemsToFire;
    }

    public void setCountItemsToFire(int countItemsToFire) {
        this.countItemsToFire = countItemsToFire;
    }

    private int countItemsToFire = 1;

    @Override
    public boolean isActive() {
        return true;
    }

    @Override
    public void run() {
        ICollection collection = collectionRegistry.getCollection(collectionId);
        Collection items = collection.getItems(null);
        if (items.size() >= countItemsToFire) {
            if (collectionHandler != null) {
                collectionHandler.handleCollection(collectionId, collectionRegistry, items);
            }
        }
    }

    public CollectionRegistry getCollectionRegistry() {
        return collectionRegistry;
    }

    public void setCollectionRegistry(CollectionRegistry collectionRegistry) {
        this.collectionRegistry = collectionRegistry;
    }

    public String getCollectionId() {
        return collectionId;
    }

    public void setCollectionId(String collectionId) {
        this.collectionId = collectionId;
    }
}
